<?php

class Application_Model_Users {

   protected $_dbTable;


    public function getdbTable() {
         if (null === $this->_dbTable) {
            $this->setDbTable('Application_Model_DbTable_Users');
        }
        return $this->_dbTable;
    }

    public function setdbTable($dbTable) {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function save($data)
    {
        return $this->getdbTable()->insert($data);
    }

    public function list_users($type = 'parent')
    {
        $select = $this->getdbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
                ->setIntegrityCheck(false);
        $select->where('role = ?',$type)
                ->join('parent_master', 'parent_master.user_id = users.id');
        return $this->getdbTable()->fetchAll($select);
    }
    
    public function fetchAll($limit = 5,$offset = 0)
    {
    	$select = $this->getdbTable()->select('*')->limit($limit,$offset);
    	return $this->getdbTable()->fetchAll($select);
    }
    
    public function fetchList()
    {
    	
    }
}

